﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Threading;

namespace commonlib
{
    class DataServerApp
    {
        static DataServer thisDataServer;
        public delegate void requestSystemUpdate();

        static void Main(string[] args)
        {
            if (args.Length > 2)
            {
                thisDataServer = new DataServer(args[0], args[1], Convert.ToInt16(args[2]));
                thisDataServer.centralAdress = ConfigurationManager.AppSettings["central_directory_address"];
                thisDataServer.centralPort = Convert.ToInt16(ConfigurationManager.AppSettings["central_directory_port"]);
                thisDataServer.requestUpdateSystemTimeOut = Convert.ToInt16(ConfigurationManager.AppSettings["request_system_update_time_out"]);
                thisDataServer.requestRegister();
                //thisDataServer.initServices();

                //atualizar o estado do sistema
                DataServerApp.requestSystemUpdate systemUpdateDlgt = new DataServerApp.requestSystemUpdate(thisDataServer.requestSystemUpdate);
                Thread thread1 = new Thread(new ThreadStart(systemUpdateDlgt));
                thread1.Start();
            }
            else
            {
                Console.WriteLine("Não foram passados parametros suficientes para iniciar o Data server.");
            }

            Console.ReadKey();
        }

    }
}
